package com.example.demo.service.impl;

import com.example.demo.manager.RedisMongoManager;
import com.example.demo.pojo.ResultResp;
import com.example.demo.pojo.UserTenantDo;
import com.example.demo.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author CHAS
 * 2024/7/27 9:41
 **/
@Slf4j
@Service
public class RedisAndMongoTemplateServiceImpl {
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private RedisMongoManager redisMongoManager;
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Resource
    private RedisTemplate redisTemplate;
    public ResultResp redisSetHash() {
        boolean b = redisUtils.setHash("testSetRedisHash", "name", "张三", 60*60*24);
        System.out.println("修改demo3名称为demo成功");
        stringRedisTemplate.opsForHash().put("testSetRedisHash", "name", "李四");
        redisTemplate.opsForHash().put("testSetRedisHash", "name", "王五");
        return new ResultResp(b);
    }

    public ResultResp deleteRedisHash() {
        return new ResultResp(redisUtils.deleteHash("testSetRedisHash", "name"));
    }

    public ResultResp mongoInsert() {
        UserTenantDo userTenantDo = UserTenantDo.builder().tenantId("1").adminStatus(1).loginName("admin").status(1).build();
        return new ResultResp(redisMongoManager.insert(userTenantDo));
    }

    public ResultResp getRedisHash() {
        log.info("获取redis中hash值");
        System.out.println(redisUtils.getHash("testSetRedisHash", "name"));
        return new ResultResp(redisUtils.getHash("testSetRedisHash", "name"));
    }
}
